import { Component, OnInit } from '@angular/core';
import { HeroService } from '../../../services/hero.service';
import { StorageService } from '../../../services/storage.service';
import { NzMessageService,NzModalService } from 'ng-zorro-antd';
import { options } from '../../../common/areaoption';
@Component({
  selector: 'app-tenantlist',
  templateUrl: './tenantlist.component.html',
  styleUrls: ['./tenantlist.component.css']
})
export class TenantlistComponent implements OnInit {

  loading = true;
  btn_loading=false;
  public tenantlist:Array<any>=[];
  public province:string;
  public city:string;
  public district:string;
  public mobile:string='';
  public companyName:string='';
  public name:string='';
  public status:string='';
  public PageIndex:number=1;
  public PageSize:number=10;
  public PageTotal:number;
  public nzOptions = options;
  public values: Array<any> = [''];
  public _values: Array<any> = [''];
  public onChanges(values: any): void {
    this.values=values;
    this._values=values;
    console.log(this.values);
  }
  constructor(private heroService: HeroService,
              private message: NzMessageService,
              private modalService: NzModalService,
              private storageService: StorageService) { }

  ngOnInit() {
    this.getTenantlist();
  }

  //获取租户列表数据
  getTenantlist(){
    this.btn_loading=true;
    if(!this.values[0]){
      this._values[0]="";
    }
    if(!this.values[1]){
      this._values[1]="";
    }
    if(!this.values[2]){
      this._values[2]="";
    }
    let url=host+"/main/merchantConnectUser/list";
    let model="companyNameLike="+this.companyName+"&nameLike="+this.name+"&mobileLike="+this.mobile+"&page="+this.PageIndex+"&pageSize="+this.PageSize;
    this.heroService.post(url,model).then(result=>{
      this.btn_loading=false;
      if(result.code==0){
        this.tenantlist=result.data.pageBean.result;
        this.province=result.data.province;
        this.city=result.data.city;
        this.district=result.data.district;
        this.PageIndex=result.data.pageBean.curPage;  
        this.PageTotal=result.data.pageBean.totalRow;
        this.loading=false;
      }else{
        this.modalService.error({
          nzTitle: '提示',
          nzContent: result.msg
        });
      }
    })
  }

  delete(value){
    console.log(value);
    let url=host+"/main/merchantConnectUser/del";
    let model='id='+value;
    this.heroService.post(url,model).then(result=>{
        console.log(result.code);
        if(result.code==0){
          this.message.success('删除成功！');
          this.getTenantlist();
        }else{
          this.message.success(result.msg);
        }
    })
  }
  //分页
  PageIndexChange(event){
    this.PageIndex=event;
    this.getTenantlist();
  }
  
  //导出Excel
  exportOut() {
    const token = this.storageService.getItem("token");
    window.location.href = host + "/main/merchantConnectUser/excelExport?token="+token+"&companyNameLike="+this.companyName+"&nameLike="+this.name+"&mobileLike="+this.mobile;
  }
}
